import React from "react"
import { useGlobalDispatch } from '@jiatuan/hooks'
import { useStripes } from '@jiatuan/yunhan-core'

function LangButton() {
    const globalDispatch = useGlobalDispatch()
    const stripes = useStripes()

    return (
        <div
            style={{ padding: '0 5px', cursor: 'pointer' }}
            onClick={() => {
                const lang = stripes.locale === 'zh-CN' ? 'en-US' : 'zh-CN'

                globalDispatch({
                    type: 'setLang',
                    payload: {
                        lang
                    }
                })

                stripes.setLocale(lang)
            }}
        >
            {stripes.locale === 'zh-CN' ? 'EN' : '中文'}
        </div>
    )
}

export default LangButton